///////////////////////////////////////////////////////////
//  CCheckListView.cpp
//  Implementation of the Class CCheckListView
//  Created on:      21-Sep-2013 9:36:12 AM
//  Original author: Jakkaphan Aiemcharoenjit
///////////////////////////////////////////////////////////

#include "CItemView.h"
#include "ControlCommand.h"
#include "IInt.h"
#include "stdafx.h"

using namespace UI::CMD;

UI::CItemView::CItemView( IItem* itemData, IChoices* choicesData, IWindowDirector* director)
{
  this->m_item = itemData;
  this->m_choices = choicesData;
  this->m_parentWnd = director;

  this->SetAttribute("width",   "100%");
  this->SetAttribute("height",  "50");
  this->SetAttribute("backgroundColour", CColour(COLOUR_PAGE));

  CLabelPtr label = CreateLabel(CAttributes()
    .Set("name",    "labelName")
    .Set("caption", this->m_item->GetName().c_str())
    .Set("x1", 0)
    .Set("y1", 0)
    .Set("width", "50%")
    .Set("height", "100%")
    );

  this->AddChild(label);

  CButtonPtr button = CreateButton(CAttributes()
    .Set("name",    ">")
    .Set("x1", "85%")
    .Set("y1", 0)
    .Set("caption", ">")
    .Set("width",   "15%")
    .Set("height",  "100%"));

  button->SetEventHandler("click", this, &CItemView::OnClickedButton);

  this->AddChild(button);

  label = CreateLabel(CAttributes()
    .Set("name",    "choiceName")
    .Set("x1", "50%")
    .Set("y1", 0)
    .Set("caption", choicesData->GetChoice(dynamic_cast<IInt*>(itemData->GetData())->GetValue()).c_str())
    .Set("width", "35%")
    .Set("height", "100%")
    .Set("fontAlignH", "right")
    );
  this->AddChild(label);
}

UI::CItemView::CItemView( IHeader* headerData )
{
  this->SetAttribute("width",   "100%");
  this->SetAttribute("height",  "50");

  CLabelPtr label = CreateLabel(CAttributes()
    .Set("name",    "labelName")
    .Set("caption", headerData->GetName().c_str())
    .Set("width", "50%")
    .Set("height", "100%")
    .Set("fontStyle",  "bold")
    );

  this->AddChild(label);
}

UI::CItemView::~CItemView()
{

}

bool UI::CItemView::OnClickedButton( CButton* button )
{
  ControlCommand::GetInstance()->OnEdit(ControlCommand::CHOICE_CTRL);
  this->m_parentWnd->OnShowView(NULL, IViewCtrl::CHOICESVIEW_T);
  return true;
}

UI::CItemViewPtr UI::CItemView::CreateItemView( IItem* itemData, IChoices* choicesData, IWindowDirector* director )
{
  return IwNUI::CSharedPtr<UI::CItemView>(new UI::CItemView(itemData, choicesData, director));
}

UI::CItemViewPtr UI::CItemView::CreateItemView( IHeader* headerData )
{
  return IwNUI::CSharedPtr<UI::CItemView>(new UI::CItemView(headerData));
}
